package contegor.scire.core;

/**
 * {@link Task}s identifier.
 *
 * @version $Revision$
 * @author  Héctor Cirbián Pousa ($Author$)
 */
@Version("$Id$")
public class TaskId extends Id {
  private static final long serialVersionUID = 1947650324039345021L;

  protected TaskId(TransactionId fragment) {
    super(fragment);
  }

  private TaskId(Id parentId, IdFragment fragment) {
    super(parentId, fragment);
  }

  public TaskId next(boolean forSubTask) {
    IdFragment idf = this.getLastIdFragment();
    if (forSubTask || !(idf instanceof IntegerIdFragment))
      return new TaskId(this, new IntegerIdFragment(0));
    else
      return new TaskId(this.getParentId(), ((IntegerIdFragment)idf).next());
  }

  public TransactionId getTransactionId() {
    return (TransactionId)this.fragments.get(0);
  }
}
